简体   繁体   中英

Is there a way to stop a url redirecting using javascript or Jquery?

for example when you click on this flickr url: http://www.flickr.com/photos/caterpiya/5716797477/sizes/h/

The /sizes/h/ changes to /sizes/l/ how can I stop it from making this change and be given an alert through Jquery or javascript if it goes to a 404?

<script>
    function yo(){
        var href = "http://www.flickr.com/photos/caterpiya/5716797477/"
        href = href+"sizes/h/";
        window.open(href);
    }
</script>
<button  onclick="yo()">open</button>

how about using a global variable? Something like:

<script>
    var isUrlClicked = false;

    function yo(){
        var href = "http://www.flickr.com/photos/caterpiya/5716797477/"
        href = href+"sizes/h/";
        isUrlClicked = true;
        window.open("href");
    }
</script>

<button  onclick="yo()">open</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM