-1

I want to open hyperlinks in a div and stop hyperlink navigation. Ideally this should work for all links on the page "especially when debugger / console is open"

  1. How to detect if the console is open on all browsers? window.console, window.console.firebug doe not seem to work with me.

  2. I am setting the innerHTML property of my div right now which opens all the images etc in my div. I want only the text to be streamed. How do I do that? This is my code:

    function load_home(){
        document.getElementById("main").text='<object type="text/html" data="my link path" ></object>';
    }
    
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
user1079065
  • 2,085
  • 9
  • 30
  • 53
  • Try using iframe to display a different site: https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe – fodma1 Dec 13 '15 at 19:49
  • There are some hacks how to detect if console is opened, but I don't think you can find universal solution for all browsers. For chrome you can try approach from [this thread on SO](http://stackoverflow.com/a/30638226/2508019). – Rudolf Gröhling Dec 13 '15 at 20:01

1 Answers1

0

To stop links from directing you to another page (what I'm assuming you mean by "hyperlink redirection"), use JavaScript to stop them with an event listener and preventDefault(). Try adding this to your code:

var links = document.getElementsByTagName("a");
for(var i = 0; i < links.length; i++) {
    links[i].addEventListener("click", function(event) {
        event.preventDefault();
    });
}

And in that anonymous function in the event listener, you can add the code to load / redirect as wished.

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94