SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    is stopping an alert() possible?

    I have an alert as one of the first things in my script. I've been wondering if it is possible for others to disable that alert if they embed my script? It's not in a function.

    Thanks
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,263
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Yup. They can redefine alert to do something else.

    PHP Code:
        var oldAlert alert;

        
    // replace alert with different function
        
    var alert = function (message) {
            
    console.log(message);
        };

        
    alert('Hello, World!');

        
    // restore original alert
        
    alert oldAlert
    "First make it work. Then make it better."

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,806
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Including alert() calls in a live script is not a good idea. Do you really want some of your visitors to be asked if they want to disable JavaScript for the page

    alert.gif

    The bottom line of that alert along with the checkbox are built in by the browser so that appears regardless of the message in one browser. Several other browsers ask if you want to disable all alerts if you display a second one. This makes them far more useful for debugging purposes but makes alerts useless for live pages - unless oyu override the alert call to generate your own dialog.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    if live then
    response.write "if(!(\^https?\:\/\/(www\.unitingrhyhtms\.com)|(www\.livescript\.co\.uk)).test(top.location.href)) alert(""belongs to " & site_name & """);"
    end if
    I think.

    I had a think about this while I was out. Just like a HTML file the javascript is outputted as a "string" from the server to the browser, so there are loads of both server and client-side ways to bypass that.

    I was trying to stop bots and scrappers and people not in the myLiveFriends list adding it to their website. I was hoping it would make loads of pop-ups in programmes running scrappers. I noticed tonight that the unitingrhythms website was doing it on its own, even when fromthat site. It shouldn't, and the livescript site doesn't though.

    Maybe the easiest and least processor intensive way to handle that is just to give them the info they want as fast as you can
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ah, a CSS dude. Thought I remembered right. Had to check your profile.

    How about a css div or something for those? with everything set inline?

    I want to allow them to have the data, but with something to let them know where it originates from if not in a list
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •