Quick Coding Question

This forum is for general topics.

Moderator: Moderators

Post Reply
bigcfk
Posts: 1356
Joined: Sat Jun 26, 2004 1:44 pm
Location: WI

Quick Coding Question

Post by bigcfk »

So i've got some code:

Code: Select all

<script type="text/javascript">
loc = window.location.href;
loc = (loc.indexOf('?') != -1)? loc.substring(0,loc.indexOf('?')) : loc;
alert(loc);
</script>
it opens a pop-up before loading and displays the URL.
I'd like to 1) take that url, 2) add ?m=1 to the end, then 3) have a text link.

And I have to do it in html because its on blogger.
but I don't know how to make it a text link.


This is my first venture to the second dream level of coding.
plasma2002
Posts: 2250
Joined: Mon Jan 12, 2004 9:42 pm
Location: Riverside, Ca
Contact:

Re: Quick Coding Question

Post by plasma2002 »

You can add ?m=1 to the end of the variable by putting a plus sign on the text...

Code: Select all

var mloc = loc + "?m=1";
As for a text link, what exactly do ya mean? Your variable mloc (if using the above example) will be the actual text of the URL... you can do whatever you want with that text, whether it be just print it on the page as text, or stick it in a <a> tag to be a link, or whatever.

HTH
[quote]Plasma: This thread is now about how everyone from England has a melty face
Quirk: I second this motion. All in favor?
cokalsM: Im drunk.
bigcfk: i'm too.
Quirk: The motion has passed. The topic of discussion is now Beanie Babies.[/quote]
^ m_m, summed up.
bigcfk
Posts: 1356
Joined: Sat Jun 26, 2004 1:44 pm
Location: WI

Re: Quick Coding Question

Post by bigcfk »

some more searching gave me this:
<script type="text/javascript">
loc = window.location.href;
loc = (loc.indexOf('?') != -1)? loc.substring(0,loc.indexOf('?')) : loc;
var mloc = loc + "?m=1";
var linkText = "Mobile View";
var theUrl = mloc;
document.write(linkText.link(theUrl));

</script>
which works perfectly, but the font appears a little off.
http://kconor.blogspot.com/ (right underneath the banner)
It's a pixel or so too high. I think that's just the way the font/color worked out, but is there anyway to shift it?
Post Reply