UIWebVIew Javascript Document.location - javascript

I have been unable to get my UIWebView to change location based in javascript. While this may seem a bit redundant, it is necessary because the client's website stores a cookie when document.location is known. However, when I try accessing the next part of his site, it will not open.
Here is the code
[self.webView stringByEvaluatingJavaScriptFromString:#"document.location = 'http://www.nextLink.com'"];
However, this doesn't seem to have done anything. Also the document.write method works!
Thanks!

Have you tried with window.location instead?

Related

How to use window.open(url,"_blank") without changing calling application's url?

This is my js window.open() code.
var url = "https://www.google.com"
window.open(url, "_blank", "menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes,width=640,height=480", false);
It opens a new browser window with the "url" as expected.
But the issue is that, it also changes the current url in my main web application.
For example before my window.open() call if I was on this url:
https://example.com/#!/projects/56asda/view
After the call the url redirects to this:
https://example.com/#!/
How can this issue be prevented? I have not found any solution for this on the internet.
I am using angularjs 1.0 for my frontend.
Please refrain from answering that "_blank" should work etc.
Any help will be invaluable.
I have tried to duplicate your issue but I have found no issues while executing the code which would mean your issue might be related to your web server settings.
Anyways, have you tried calling it like this:
var url = "https://yourlink.here";
window.open(url, "_blank");
Without anything like "menubar=no" or other arguments?
If you haven't, I suggest you do and if that works, just add the arguments one by one to check which one contains the error.

I want a codes which redirect to my website when JavaScript used on wrong site

I want to secure JavaScript Codes. I secure my JavaScript with https://javascriptobfuscator.com/ but it can also stolen from view source.
I want a codes which redirect to my website when JavaScript used on wrong site.
This is possible I know but I don't know how?
What you could do is check the return of location.host or location.hostname.
To redirect to another URL you would change the value of location:
location = "https://mywebsite.com";
//or alternatively
location.assign("https://mywebsite.com");
However, the redirection may will be prevented by Cross-origin resource sharing policies (see Michael's comment). So you could just display an alert dialog.
alert("Don't use my script on your website");
The person trying to use your code on their website will be warned during development by this alert.
In any case, your obfuscated code can still be changed and someone that is determined will remove these "security" measures and it can even be deobfuscated.
Are you sure all of this is needed ? Modifying a stolen code to make it work on another website can be harder/longer than just rewriting a similar code. Apart if you are doing something very special and new, I think you are just losing time by trying to protect your code.

Reload a page once on start for IE9 users with JavaScript

I would like a page to force reload once for IE9 users to clear the cache. I've been experimenting with this function:
location.reload();
The question: is it possibly to target people using IE9 and only reload ONCE on load.
Thankful for any help I can get.
/Linus
It would probably be best if you could devise some strategy which allows you NOT to depend on the browser version.
Having said that, here is a link that will allow you to detect IE9.
reference : stackoverflow similar question
from the link to answer taken
Two options:
1- You can use cookies. Set a cookie when logging in and check for
that during load. Then clear it after performing your initialization
so that next load the check will fail.
2- You can use the address, either as a parameter like ?justLoggedIn,
or a value in the hash after #justLoggedIn. Then check for that and
redirect to the same url minus the justLoggedIn part. The advantage of
the # version is that it doesn't actually reload the page, unlike when
using the ? version.
UPDATE:
reference :stackoverflow similar question
I'd say use hash, like this:
window.onload = function() {
if(!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload();
}
}
UPDATE 2:
i think you should take a look at this question
i dont know about pjax until now so i dont know alot about it
stackoverflow question
look at http://pjax.heroku.com/in the answers

javascript: will window.location make any warnings?

If I use window.location = ""; to redirect a user, will any browsers give the user a warning message (since the page is redirecting without the user's consent)?
Should I use window.location = "" or window.location.href = ""?
No you can redirect the window location on your own. The only similarly related thing you can't do automatically is click a link for the user with an event.
You might be thinking of this type of notice:
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}
No. You will not get any warning (like you do if you close the window). And I have never seen any difference in location and location.href, but I use the last :)
AFAIK window.location and window.location.href should be pretty much eqivalent.
It's been a while since I've used it, but I don't remember ever seeing a prompt before leaving the page. Most of the time when I have been prompted it's been because I explicitly put a confirmation in, such as when clicking a link to delete something.
Setting window.location shouldn't cause any issues with redirection. However, if there is a hash, then some browsers may deal with it differently.
From the MDN spec:
Note: The example above works in situations where window.location.hash does not need to be retained. However, in Gecko-based browsers, setting window.location.pathname in this manner will erase any information in window.location.hash, whereas in WebKit (and possibly other browsers), setting the pathname will not alter the the hash. If you need to change pathname but keep the hash as is, use the replace() method instead, which should work consistently across browsers.
There shouldn't be any difference between location and location.href since whenever a property of the location object is modified, a document will be loaded using the URL as if window.location.assign() had been called with the modified URL.
Source: https://developer.mozilla.org/en/DOM/window.location

How can I write something in browser's address bar with JavaScript after the page is completely loaded?

How can I write something ("hello my client" for example) in the browser's address bar with javascript after the page is completely loaded?
Mean writing something in address bar without entering - is it possible?
It seems we can do this job with JavaScript, if not can we do that with server side code?
How?
This is possible, but only the part after the hostname:
history.pushState(null, "page 2", '/foo.html');
Try this in your javascript console, this effectively changes the current path with /foo.html. (It's a new html5 feature, and is available in recent browsers only.)
See mozilla docs: https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries
Browser Compatibility
Why?
This is used to make ajax sites history/bookmark/link friendly by updating the URL as the content is updated. Currently most sites do this by only changing the hash part of the URL (e.g. Twitter with their #!.)
For instance Github uses this for their code browser: https://github.com/blog/760-the-tree-slider
Maybe its already answered # Change the URL in the browser without loading the new page using JavaScript .
You can set location.hash, but you can't replace the entire URI.
The reason this is not possible is it presents a security violation. This is why phishers write a gif file over where they believe the address bar will be.
My question is why would you want to do this? The only reason I can think of is you want to make someone think they are at http://Iamreallyyourbank.com when they are at http://IamStealingYourMoney.com, which is why the security is in place.
This is not possible. You cannot change the URL displayed in the browser. Not only would it be a horrible security practice, it would be a violation of trust to the people visiting your site.

Categories

Resources