How to open some pages by one HyperLink item? - c#

I have an array of some URL links. And I need to open all theese links by clicking one HyperLink, located in cell of Telerik GridHyperLinkColumn.
Is there any method to do this?
Now I have a code which sets first way to my HyperLink:
HyperLink link = (HyperLink) item["documents"].Controls[0];
if (link.NavigateUrl.Contains(";"))
{
string[] linktext = link.NavigateUrl.Split(';');
link.NavigateUrl = linktext[0];
}

I would probably take a quick look at this SO answer here.
The takeaway is that this is not possible without using JavaScript functions:
Without JavaScript, it's not possible to open two pages by clicking
one link unless both pages are framed on the one page that opens from
clicking the link. With JS it's trivial.
The example is this:
<p><a href="#" onclick="window.open('http://google.com');
window.open('http://yahoo.com');">Click to open Google and Yahoo</a></p>
This would also work: (again see answer here)
Open Two Links With One Click

Related

Find and click a link with text - Coded UI

I am trying to create a test that finds a specified link on a web page and clicks it. What I am attempting to do is search for the link by specifying the name/text of the link. Is there a way to create a hyperlink object solely by specifying this?
I can do the following to find the link by specifying the href property like this:
BrowserWindow browser = BrowserWindow.Locate("Window Title");
var hyperlink = new HtmlHyperlink(browser);
hyperlink.SearchProperties.Add(HtmlHyperlink.PropertyNames.Href, "link.com");
Mouse.Click(hyperlink);
But I want to do the same thing by specifying the text/name of the link.
Any help would be appreciated! Thanks
I solved it...
This finds the link based on the text:
hyperlink.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "text");

html <pre></pre> page layout blocks links

I am taking a document into an html page to show the user with .Net libraries' help. I am using LoadHtml method under HtmlAgilityPack. But when i use that method to fill the html, it does not show the tab(ascii=09) characters right. So i use it like:
doc.LoadHtml("<pre>" + pContent + "</pre>");
But when i do that then i can not add any picture links or pictures to the html page. normally before i use "< pre >", the user was able to add links. The code below was running behind.
string text = string.Format(#"<img src='{0}' />", thepicturelink);
My problem is that i want to make my page both could be added links(pictures) and looks proper with tab character. I could not find any solution for that in here, msdn, socialmsdn, codeproject or google. Does anyone have a solution for that problem? Thank for helps. Best regards.

html: perform other actions after following a href link

Background
Here's what I want to happen:
A user is on one page1.html (jsFiddle).
When they click on one of the <a href...> links, I want to navigate to page2.html (jsFiddle) and simulate the user entering the number into the textbox and clicking on the button.
Example: On page1.html, user clicks on display 2. Then we will navigate to page2.html and get an alert of 2 (as if user had entered 2 and clicked the button).
Question
How do I do this?
Is there a way to make a C# method with a specific URL to navigate to, such as page2.html/searchfor/2?
Or is there some way in JavaScript to manually go about doing other things after navigating to <a href="page2.html">?
Things I've tried
Using a <span> with an onclick function, but then it's not a true link like <a href> where I can middle click to open in new tab and right click to follow link
Wrapping my first attempt in <a href> tags, like <span>Display 2</span>. This still doesn't solve the problem of performing extra actions after navigation.
Note
I am building this webpage using Entity Framework, ASP.NET MVC, and C#.
I have simplified the problem for discussion purposes, but the concept is the same.
Try using the page2.html document's onload() function. You can pass parameters through the URL, then take that data and perform "other actions" as soon as the document is loaded.

ASP.net Passing Links from Page to Page

I am trying to display a page into an IFrame.
The IFrame is displayed into a fancyBox overlay popup.
I have a list with the http links (gets compiled at runtime and it constantly changes).
Using a global variable I can access the list with the links.
But the http link in the list must match the link I have clicked.
If I can even get the link which I have clicked it will also be enough (the link brings up a fancyBox popup so it doesn't actually bring up a new page so to speak)
How to do that?
You have to write some tricky code to achieve this, main goal is to edit the dynamically added page content by adding wrapper tag (with onclick event) around all the links, writing javascript to be called using that wrapper to findout which link has been clicked,
You can try this by doing following steps
1) Get the content of IFrame , using the following JQuery code you can get the content of IFrame
var $currentIFrame = $('#myIFrame');
var content = $currentIFrame.contents();
2) Now manupulate these content by finding all the links inside that page and wrapping them with a tag that should have onclick event e.g. span , you have to write some javascript function to fire on a link if user clicks it.
see the following link for how to manipulate content
Get all links inside iframe and add blank target attribute

Click an HTML link inside a WebBrowser Control

C# Visual Studio 2010
I am loading a complex html page into a webbrowser control. But, I don't have the ability to modify the webpage. I want to click a link on the page automatically from the windows form. But, the ID appears to be randomly generated each time the page is loaded (so I believe referencing the ID will not work).
This is the content of the a href link:
<a
id="u_lp_id_58547"
href="javascript:void(0)"
class="SGLeftPanelText" onclick="setStoreParams('cases;212', 212); window.leftpanel.onClick('cases_ss_733');return false; ">
My Assigned</a>
Is the anyway to click the link from C#?
Thanks!
UPDATE:
I feel like this is close but it is just not working:
HtmlElementCollection links = helpdeskWebBrowser.Document.Window.Frames["main_pending_events_frame"].Document.GetElementsByTagName("a");
MessageBox.Show(links.Count.ToString());
I have tried plugging in every single frame name and tried both "a" and "A" in the TagName field but just have not had any luck. I can just not find any links; the message box is always 0. What am I missing?
Something like this should work:
HtmlElement link = webBrowser.Document.GetElementByID("u_lp_id_58547")
link.InvokeMember("Click")
EDIT:
Since the IDs are generated randomly, another option may be to identify the links by their InnerText; along these lines.
HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("My Assigned"))
link.InvokeMember("Click");
}
UPDATE:
You can get the links within an IFrame using:
webBrowser.Document.Window.Frames["MyIFrame"].Document.GetElementsByTagName("A");
Perhaps you will have to isolate the link ID value using more of the surrounding HTML context as a "target" and then extract the new random ID.
In the past I have used the "HtmlAgilityPack" to easily parse "screen-scraped" HTML to isolate areas of interest within a page - this library seems to be easy to use and reliable.

Categories