472,783 Members | 1,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

Select SOME text from a page and use it as a var

If I open a new page with very little text on it such as
a bugmenot
results page
is there a way to select some of the text there and
assign it to variables?
Selecting all and copying to the clipboard can be done with:
document.execCommand("SelectAll");
document.execCommand("Copy");
but I'm looking for something a little more refined.

The page contains seven lines of text and I'd like a simple way to say:
var username = [contents of line 4]
var password = [contents of line 5]
Can anyone point me in the right direction?

Jul 23 '05 #1
4 1653
On 16 Dec 2004 06:31:44 -0800, melvynadam wrote:
If I open a new page with very little text on it such as
a bugmenot
results page
is there a way to select some of the text there and
assign it to variables?


on the fly:

function getCurrentSelection(){
if (window.getSelection)
return typeof window.getSelection().toString();
else if (document.getSelection)
return document.getSelection()
else if (document.selection && document.selection.createRange)
return document.selection.createRange().text;
else
return null;
}

var sel=getCurrentSelection();

maybe it could be help you.

--
ZER0

~ The Tangent Universe collapsed 5891 days, 9 hours, 2 minutes and 6 seconds ago.

on air ~ "(Unknown Artist) - The Artifact And Living"
Jul 23 '05 #2
Thanks for the incredibly quick response! Unfortunately it's not quite
what I'm looking for - I want the process to be automated. If I have to
manually select the text it negates the point of the plugin I'm trying
to create.
I wish to open a bugmenot results page using my current location (e.g.
www.nytimes.com) with this line:
window.open('http://www.bugmenot.com/view.php?mode=bookmarklet&url='+document.location, 'click','height=300,width=400,title=no,location=no ,scrollbars=yes,menubars=no,toolbars=no,resizable= yes');
Then, in the new window I wish to automatically select the only text on
that page which changes (take a look at
http://www.bugmenot.com/view.php?mod...ww.nytimes.com
if you copy and paste all of the text you'll see that it's nicely
formatted and the two desired fields are on their own on individual
lines).
Later I'll want to try to return to the original page and find the
fields "user" or "username" etc. and paste back my results.

Jul 23 '05 #3
On 16 Dec 2004 07:01:12 -0800, melvynadam wrote:
I wish to open a bugmenot results page using my current location (e.g.
www.nytimes.com) with this line:
window.open('http://www.bugmenot.com/view.php?mode=bookmarklet&url='+document.location, 'click','height=300,width=400,title=no,location=no ,scrollbars=yes,menubars=no,toolbars=no,resizable= yes');
Then, in the new window I wish to automatically select the only text on
that page which changes (take a look at
http://www.bugmenot.com/view.php?mod...ww.nytimes.com


Wait, let me understand (I'm sorry, but my english is not very good)..

You have a page in a domain (http://www.nytimes.com); and you want open a
popup that points in other domain (http://www.bugmenot.com/), and after get
some information from this?

In according with SOP (Same Origin Policy), you cannot do it:

http://www.mozilla.org/projects/secu...me-origin.html

--
ZER0

~ The Tangent Universe collapsed 5891 days, 9 hours, 26 minutes and 52 seconds ago.

on air ~ "donny darko - Mad World (full version)"
Jul 23 '05 #4
"melvynadam" <me*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
If I open a new page with very little text on it such as
a bugmenot
results page
is there a way to select some of the text there and
assign it to variables?
Selecting all and copying to the clipboard can be done with:
document.execCommand("SelectAll");
document.execCommand("Copy");
but I'm looking for something a little more refined.

The page contains seven lines of text and I'd like a simple way to say:
var username = [contents of line 4]
var password = [contents of line 5]
Can anyone point me in the right direction?


Will this help? Watch for word-wrap.

<html>
<head>
<title>bugmenot.htm</title>
<script type="text/javascript">
function bugmenot() {
var sWWW = http://www.bugmenot.com/view.php?url=;
var sURL = document.getElementById("URL").value;
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sWWW+sURL,false);
oXML.send();
try {
var sXML = oXML.ResponseText;
var iDD1 = sXML.indexOf("<dd>");
var iDD2 = sXML.indexOf("</dd>");
var sVAL = sXML.substr(iDD1+4,iDD2-iDD1-4);
var sUSR = sVAL.substr(0,sVAL.indexOf("<"));
var sPWD = sVAL.substr(sVAL.indexOf(">")+1);
document.getElementById("USR").value = sUSR;
document.getElementById("PWD").value = sPWD;
document.all.i.src = sWWW+sURL;
} catch(e) {
alert(sWWW + sURL + " Failed!");
}
}
</script>
</head>
<body>
<center>
<form>
<table border="0" width="600">
<td align="center">
<b>Enter a URL: </b>
<input type="text" name="URL" id="URL" size="30"
value="www.nytimes.com">
&nbsp;
<input type="button" value="Bug Me Not!" onclick="bugmenot()">
</td>
<tr>
</tr>
<td align="center">
<b>Username: </b>
<input type="text" name="USR" id="USR" readonly>
&nbsp;
<b>Password: </b>
<input type="text" name="PWD" id="PWD" readonly>
</td>
</tr>
</table>
</form>
<iframe name="i" align="center"
frameborder="1" scrolling="no"
marginwidth="0" marginheight="0"
style="width:600; height: 380"></iframe>
</body>
</html>
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JT | last post by:
I have an input form for which I've created a "matrix" for user input. Basically, the user chooses a radio button and then through javascript, a select box is displayed to define a value for that...
4
by: point | last post by:
Hello there... I'm a PHP programmer and starting to learn JS... I have a following problem.... I have 3 select boxes! one is hotel one is destination and one is country... if someone...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
by: Cali | last post by:
Please bear with me, I have been reading about XSL for a couple hours. I have an XML document that contains multiple <page> tags interspersed throughout the tree. <text> .... <page>1</page>...
1
by: Mad Scientist Jr | last post by:
I'm stuck trying to work with a HTML <SELECT> control and javascript (similar to DualList but that control doesn't offer enough options to totally control the text on the buttons and control, also...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
4
by: rn5a | last post by:
A Form has 2 select lists. The 1st one whose size is 5 (meaning 5 options are shown at any given time) allows multiple selection whereas the 2nd one allows only 1 option to be selected at a time. ...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.