0

How can I set the documentURI to a website of my choice. In a javascript function I have:

var sitePage = document;
sitePage.documentURI = "www.google.com" 

Does not work, the URL stays on the original page.

Ideally I would like to click on an link in the page using its id:

sitePage.getElementById("link").Click();

But I get

'Type Error: cannot read property 'click' of 'null'

I have "link" and "www.google.com" as strings in 2 variables.

Cedric
  • 117
  • 1
  • 12
  • Firstly, `window.location.href = "www.google.com"`, secondly -> [Why does jQuery or a DOM method such as getElementById not find the element](http://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – adeneo Mar 02 '16 at 22:05
  • I do know why the getElementById does not find the element it is because currPage is still reffering to the original page, even with window.location.href = "www.google.com" – Cedric Mar 02 '16 at 22:12
  • I think you're a bit confused there? Once you call `window.location.href` you leave the page, all javascript will be lost, and the browser moves on to Google, where you don't have access to ... anything, you can't run javascript on Googles pages. – adeneo Mar 02 '16 at 22:33
  • I now, it is why I am trying to stay on my page but via document click on this link referenced by an id on the sitePage – Cedric Mar 02 '16 at 22:41

0 Answers0