ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Unfinished Requests

UNANSWERED: Bookmarklet to replace 'user-scalable=0' with 'user-scalable=1'

(1/3) > >>

lujomu:
I would like to remove the zoom restrictions for mobile web pages on my Android phone (should also work on iPhone/iPad), because my sight is not the best and some fonts are just too tiny for me to read on that little display.

If I researched correctly, the restriction is caused by the 'user-scalable=0' argument of the 'viewport' meta tag, e.g.

--- ---<meta content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport' />
I thought it might be possible to replace this 'user-scalable=0' with a 'user-scalable=1' (or remove it alltogether) using a bookmarklet. Unfortunately I don't know any JavaScript, so could someone please help me out on that?


lujomu:
As I got not a single reply in almost five month, I hope it's alright that I bump this topic once: bump.

ewemoa:
The following is something that I tried out via Firebug on http://en.m.wikipedia.org/:


--- Code: Javascript ---(function ()  {    var elts = document.getElementsByName("viewport");    var attrval = "";    /* XXX: this is not quite right */    var cntRe = /(user-scalable\s*=\s*0)/i;    var i = 0;    for (i = 0; i < elts.length; i++)    {      attrval = elts[i].getAttribute("content");      if (cntRe.test(attrval))      {        elts[i].setAttribute("content", attrval.replace(cntRe, "user-scalable=1"));      }    }  })();
When I examine the DOM before and afterwards, it looks like may be it's working.  Haven't converted it into a bookmarklet to test that way yet.  May be there are other folks who can join in to test :)

Update: Changed comment // -> /* */ to facilitate bookmarklet conversion.

ewemoa:
I pasted the following as the content of the Location field in a bookmark in Firefox 4.0.1:


--- Code: Javascript ---javascript:(function () { var elts = document.getElementsByName("viewport"); var attrval = ""; var cntRe = /(user-scalable\s*=\s*0)/i; var i = 0; for (i = 0; i < elts.length; i++) { attrval = elts[i].getAttribute("content"); if (cntRe.test(attrval)) { elts[i].setAttribute("content", attrval.replace(cntRe, "user-scalable=1")); } } })();
Firefox appeared to transform the content as follows (I think this was a simple replacement of spaces with %20):


--- Code: Javascript ---javascript:(function%20()%20{%20var%20elts%20=%20document.getElementsByName("viewport");%20var%20attrval%20=%20"";%20var%20cntRe%20=%20/(user-scalable\s*=\s*0)/i;%20var%20i%20=%200;%20for%20(i%20=%200;%20i%20<%20elts.length;%20i++)%20{%20attrval%20=%20elts[i].getAttribute("content");%20if%20(cntRe.test(attrval))%20{%20elts[i].setAttribute("content",%20attrval.replace(cntRe,%20"user-scalable=1"));%20}%20}%20})();
This appeared to work on http://en.m.wikipedia.org/.

Note: the regular expression used could probably use some improvement.

lujomu:
Hi ewemoa!

Let me start by expressing my gratitude for taking time trying to help me!

I did not get it to work yet, however I think it is the fault of Android or the Android Browser respectively.

Here is what I tried:
I took your script and deleted the line breaks, comments and unnecessary spaces and added two 'alert' functions, to see if the script is executed at all:


--- Code: Javascript ---javascript:(function(){alert("start");var%20elts=document.getElementsByName("viewport");var%20attrval="";var%20cntRe=/(user-scalable\s*=\s*0)/i;var%20i=0;for(i=0;i<elts.length;i++){attrval=elts[i].getAttribute("content");if(cntRe.test(attrval)){elts[i].setAttribute("content",attrval.replace(cntRe,"user-scalable=1"));}}alert("end")})();
Then I tried it with the following browsers (on the phone):

* Android Browser
* Firefox Beta v5.0
* Dolphin Browser HD Beta v5.0.2
* Miren Browser v1.2
Only Firefox executes the script (prints the 'end' message twice btw.), but it has no effect on the webpage. The other three browser choke already on the following lines (without the 'var...' line they can execute the script though):


--- Code: Javascript ---javascript:(function(){alert("start");var%20attrval="";alert("end")})();
Any ideas?

Navigation

[0] Message Index

[#] Next page

Go to full version